package DataBase;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Types;
import java.util.ArrayList;
import java.util.Vector;

import DataObjects.Schedule;
import DataObjects.Table;

public class GetAllSchedules {
	
	Vector<Schedule> schedules=new Vector<Schedule>();
	


	Vector<String> namesOfSchedules;
	
	
	public void get()
	{
		SQLConnection sc=new SQLConnection();
		
		
		try {
		PreparedStatement ps = sc.getConnection().prepareStatement("SELECT scheduleName FROM  schedule  ;");	
		PreparedStatement ps2 = sc.getConnection().prepareStatement("SELECT tId,coordX,coordY,size,orientation FROM  tableschedule WHERE scheduleName=?  ;");	
		
		ResultSet rs=ps.executeQuery();		
		namesOfSchedules = new Vector<String>();
		
		 while(rs.next())
	        {   
			 namesOfSchedules.add(rs.getString(1));
	        }//while
			
		 int size=namesOfSchedules.size();
		 if(size>0)
		 { 
		 for(int i=0; i<size;i++)
			{
			   ps2.setString(1, namesOfSchedules.get(i));
			   Vector<Table> vecTables=new Vector<Table>();
			   ResultSet rs2=ps2.executeQuery();				   
			   while(rs2.next())
		        {   
				 Table table = new Table();
		         table.setNumber(rs2.getInt(1));
		         table.setX(rs2.getInt(2));
		         table.setY(rs2.getInt(3));
		         table.setSize(rs2.getInt(4));
		         table.setType(rs2.getString(5));
		         vecTables.add(table);
		         
		        }//while
			   Schedule sch=new Schedule(namesOfSchedules.get(i),vecTables);
			   schedules.add(sch);
			   rs2.close();
			}  // for(int i=0; i<size;i++)
		 }
		 
		 
		 ps.close();
		 rs.close();
		 ps2.close();
		 sc.getConnection().close();
		
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		 
		
			}
		
		
		
	public Vector<Schedule> getSchedules() {
		return schedules;
	}


	public void setSchedules(Vector<Schedule> schedules) {
		this.schedules = schedules;
	}
		
		
		
		
		
		
	
}
